package edu.xkd;

import edu.xkd.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //关联一个界面布局文件
        super.setUIContent(ResourceTable.Layout_ability_main);
        //写关于界面的后台业务逻辑
        //获取界面中的按钮对象
        Button button_01=(Button)this.findComponentById(ResourceTable.Id_button_01);
        Button button_02=(Button)this.findComponentById(ResourceTable.Id_button_02);
        //为按钮对象添加单击事件
        button_01.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                ToastDialog toastDialog=new ToastDialog(MainAbility.this);
                toastDialog.setText("按钮被单击");
                toastDialog.show();
            }
        });
        //hmos特有的绑定事件
        button_02.setClickedListener(this::clickedListenerButton02);

    }
    private void clickedListenerButton02(Component component){
        ToastDialog toastDialog=new ToastDialog(this);
        toastDialog.setText("ohos特有的绑定处理方法");
        toastDialog.show();
    }
}
